<?php

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die;

jimport('joomla.application.component.model');

class ApkipasModelApkipas extends JModel
{

	function getData($ordering = NULL) {

		$user = &JFactory::getUser();
		$db = &JFactory::getDBO();

		$app = &JFactory::getApplication();
		$params =  &$app->getParams('com_apkipas');
		$category = JRequest::getInt('id');

		$limitstart = JRequest::getInt('limitstart');
		
		$query = 'SELECT a.id as title_id , 
							a.product_id, 
							a.title as main_title, 
							a.alias, a.created_date, 
							a.meta_title ,
							b.des, 
							b.category,
							b.meta_des ,b.bg
					FROM #__apkipas_titles as a
					LEFT JOIN #__apkipas_resources as b ON a.product_id = b.id ';

		$where = array();
		$where[] = 'a.published = 1';

		if($category != 0 && $category != 8)
  			$where[] = 'a.cat_id = '.$category;

		if(count($where) > 0) {
			$query .= ' WHERE '.implode(' AND ', $where);
		}
		$query .= ' ORDER BY title_id DESC ';
		$db->setQuery($query, $limitstart, 10);
		$rows = $db->loadObjectList();
		return $rows;
	}
}
